package com.crazyhat.crazyhat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.crazyhat.crazyhat.entity.Favorite;
import com.crazyhat.crazyhat.pojo.Result;
import com.crazyhat.crazyhat.service.IFavoriteService;




/**
 * <p>
 * 收藏的社团 前端控制器
 * </p>
 *
 * @author crazyhat
 * @since 2024-07-05
 */
@RestController
@RequestMapping("/favorite")
public class FavoriteController {

    @Autowired
    private IFavoriteService favoriteService;

    /**
     * 获取收藏的社团
     * @return
     */
    @GetMapping("/personalFavorite")
    public Result<Page<Favorite>> getPersonalFavorite(@RequestParam int pageNum,@RequestParam int pageSize) {

        Page<Favorite> favoritePage = favoriteService.getPersonalFavorite(pageNum, pageSize);
        return Result.success(favoritePage);
    }

    /**
     * 收藏新社团
     * @param clubId
     * @return
     */
    @PostMapping("/favoriteNewClub")
    public Result favoriteNewClub(@RequestParam(value = "clubId") Integer clubId) {
        
        favoriteService.favoriteNewClub(clubId);
        
        return Result.success();
    }

    /**
     * 获取社团收藏状态
     * @param clubId
     * @return
     */
    @GetMapping("/favoriteState")
    public Result<Boolean> getClubFavoriteState(
        @RequestParam(value = "clubId") Integer clubId,
        @RequestParam(value = "studentId") Integer studentId
        ) {

        boolean hasFavorite = favoriteService.getClubFavoriteState(studentId,clubId);

        return Result.success(hasFavorite);
    }

    @PostMapping("/cancelFavorite")
    public Result<Boolean> cancelFavorite(
        @RequestParam(value = "clubId") Integer clubId
    ) {

        return Result.success(favoriteService.cancelFavorite(clubId));
    }
    
}
